<?php

namespace App\Models\Goods;

use App\Models\BaseModel;

/**
 * 货品属性值模型类
 *
 * @package App\Models\Goods
 */
class AttributesValue extends BaseModel
{
    protected $table = 'b2c_goods_attributes_value';
    public $timestamps = false;

    /**
     * 保存属性值
     *
     * @param int $goodsId
     * @param int $attributeId
     * @param string $value
     * @return mixed
     */
    public static function saveData(int $goodsId, int $attributeId, string $value)
    {
        $attributeValue = new AttributesValue();
        $attributeValue->goods_id = $goodsId;
        $attributeValue->attribute_id = $attributeId;
        $attributeValue->value = $value;
        return $attributeValue->save();
    }

    /**
     * 根据商品ID删除属性值
     *
     * @param int $goodsId
     * @return mixed
     */
    public static function removeByGoodsId(int $goodsId)
    {
        return AttributesValue::query()->where('goods_id', $goodsId)->delete();
    }

    /**
     * 获取商品的属性
     *
     * @param int $goodsId
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function getGoodsAttrs(int $goodsId)
    {
        return AttributesValue::query()->where('goods_id', $goodsId)->get();
    }
}
